{extend name="base"/}
{block name="resources"}
{/block}
{block name="main"}
<div class="layui-form">

    <div class="layui-card ns-card-common ns-card-brief">
        <div class="layui-card-header">
            <span class="ns-card-title">添加店铺</span>
        </div>
        <div class="layui-card-body">

            <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-inline">
                    {$user_info.username}
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">联系电话：</label>
                <div class="layui-input-inline">
                    {if empty($user_info.mobile)} 无 {else/} {$user_info.mobile} {/if}
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">店铺名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="site_name" lay-verify="required" class="layui-input ns-len-mid">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">店铺套餐：</label>
                <div class="layui-input-block">
                    <div class="layui-input-inline ns-len-mid">
                        <select name="group_id" lay-verify="required">
                            <option value="">请选择</option>
                            {foreach $group_list as $group_list_k => $group_list_v}
                            <option value="{$group_list_v.group_id}">{$group_list_v.group_name} </option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">服务到期时间：</label>
                <div class="layui-input-inline">
                    <input type="text" name="expire_time" id="expire_time" lay-verify="date|required" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input ns-len-mid" readonly>
                </div>
            </div>

			<input type="hidden" name="sys_uid" value="{$sys_uid}">
			<div class="ns-single-filter-box">
				<div class="ns-form-row">
					<button class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
				</div>
			</div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    layui.use(['form', 'laydate'], function() {
        var form = layui.form,
            laydate = layui.laydate,
            repeat_flag = false; //防重复标识

        //日期
        laydate.render({
            elem: '#expire_time'
        });

        form.render();

        form.verify({
            rate: function(value){
                if(value > 100 || value < 0 || value%1 != 0){
                    return '请填写0-100的整数';
                }
            },
			flo: function (value) {
				if (value == '') {
					return;
				}
				var reg = /^(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/;
				if (!reg.test(value)) {
					return '价格不能小于0，可保留两位小数！'
				}
			},
            check_num:function(value){
                if($("input[name='min_withdraw']").val() > value){
                    return '最小提现金额不能大于最大提现金额！';
                }
            }
        });

        form.on('submit(save)', function(data) {

            if (repeat_flag) return;
            repeat_flag = true;

            field = data.field;
            if(!field.status){
                field.status = 0
            }

            if(field.status == 1){
                if(field.day == ''){
                    layer.msg('请选择体验时长');
                    repeat_flag = false;
                    return;
                }
            }

            if(field.status == 1){
                if(field.group_id == 0){
                    layer.msg('请选择体验套餐');
                    repeat_flag = false;
                    return;
                }
            }

            $.ajax({
                type: 'POST',
                dataType: 'JSON',
                url: ns.url("admin/sysuser/addsite"),
                data: field,
                success: function(res) {

                    repeat_flag = false;
                    if (res.code == 0) {
                        layer.confirm('添加成功', {
                            title:'操作提示',
                            btn: ['返回列表', '继续添加'],
                            closeBtn: 0,
                            yes: function(){
                                location.href = ns.url("admin/sysuser/lists")
                            },
                            btn2: function() {
                                location.href = ns.url("admin/sysuser/addsite")
                            }
                        })
                    }else{
                        layer.msg(res.message);
                    }
                }
            });
        });
    });
</script>
{/block}